﻿Namespace EyeOpen.SearchFile.Windows

	Friend Class TextBoxLogger
		Implements ILogger
		Private ReadOnly textBox As TextBoxBase

		Public Sub New(ByVal textBox As TextBoxBase)
			Me.textBox = textBox
		End Sub

		Public Sub Debug(ByVal message As String) Implements ILogger.Debug
			WriteMessage("Debug", message)
		End Sub

		Public Sub Trace(ByVal message As String) Implements ILogger.Trace
			WriteMessage("Searching", message)
		End Sub

		Public Sub Exception(ByVal exception As Exception) Implements ILogger.Exception
			WriteMessage("Error", exception.Message)
		End Sub

		Private Sub WriteMessage(ByVal verbosity As String, ByVal message As String)
			textBox.Invoke(Sub()
				textBox.SuspendLayout()
				textBox.Text = String.Format("{0}: {1}{2}{3}", verbosity, message, Environment.NewLine, textBox.Text)
				textBox.ResumeLayout()
			End Sub)
		End Sub
	End Class
End Namespace